<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录页面</title>
    <script src="./jquery.min.js"></script>
</head>

<body>
    <!-- 登录表单 -->
    <form id="form1">
        <div>账号：<input type="text" name="username" autocomplete="off" /></div>
        <div>密码：<input type="password" name="password"></div>
        <button>登录</button>
    </form>
    <script>
        $(function() {
            // 监听登录表单的提交
            $('#form1').submit(function(e) {
                e.preventDefault();
                $.ajax({
                    method: 'POST',
                    url: '/api/login',
                    // 快速获取表单中数据
                    data: $(this).serialize(),
                    success: function(res) {
                        if (res.status !== 1) {
                            return alert('登录失败')
                        }
                        // // 将登录成功后的值存到本地存储
                        // localStorage.setItem('token', res.token);
                        // 跳转到后台主页
                        location.href = './index.html';
                    }
                })
            })
        })
    </script>
</body>

</html>